//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __GHOSTEVENT_H__
#define __GHOSTEVENT_H__

#include <elasys_server.h>
#include <interlocked.h>
#include "ghost.h"

class CGhostEvent: public Ghost
{
public:
    UInt32 AddRef();
    UInt32 Release();

public:
    ECode TryWait(
        /* [in] */ Millisecond32 msTimeOut,
        /* [out] */ WaitResult * pResult,
        /* [out] */ EventState * pState);

    ECode Notify(
        /* [in] */ EventState state);

    ECode Clear();

public:
    CGhostEvent() : m_hEvent(NULL) {}
    virtual ~CGhostEvent();

    ECode Initialize(
        /* [in] */ Boolean bManualReset,
        /* [in] */ EventState initState);

private:
    PVoid  m_hEvent;
private:
    Interlocked m_nRefs;
};

class CGhostEventFactory: public GhostFactory
{
public:
    ECode CreateGhost(
        /* [out] */ Ghost ** ppGhost,
        /* [out] */ Boolean * pExisted);

public:
    CGhostEventFactory(WString name,
                Boolean bManualReset,
                EventState initialState)
              : GhostFactory(name, ObjectType_NamedEvent),
                m_bManualReset(bManualReset),
                m_initialState(initialState) {}
private:
    Boolean    m_bManualReset;
    EventState m_initialState;
};

#endif //__GHOSTEVENT_H__

